﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.BlobStoring;

namespace Himp.Platform
{
    [Route("api/file/v1")]
    public class FileController : ApiBaseController
    {
        private readonly IBlobContainer _blobContainer;

        public FileController(IBlobContainer blobContainer)
        {
            _blobContainer = blobContainer;
        }

        [HttpPost("upload")]
        public async Task<IActionResult> UploadFile(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                return BadRequest("File is empty");
            }

            var bytes = await file.GetAllBytesAsync();
            await _blobContainer.SaveAsync("my-blob-1", bytes);

            return Ok($"File uploaded successfully.");
        }
    }
}
